package app;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;



public class Bbcode2html {
	
//<div style="text-align: center">
//<span style="color: blue;">
//<a href="http://www.omgubuntu.co.uk/2011/01/multi-touch-in-ubuntu-using-a-webcam-and-your-hands-video" target="_blank" rel="nofollow">
///</a>	
//<span style="font-size: 18pt;">	
//<blockquote><div class="cita"><strong></strong> dijo:</div>	
/*
 * [swf=http://www.youtube.com/v/J6k76vuw9Rk]
link: [url]http://www.youtube.com/watch?v=J6k76vuw9Rk[/url]
 * <div style="text-align: center"><br /><center><embed src="http://www.youtube.com/v/pQpr3W-YmcQ?fs=1" quality=high width="640px" height="385px" type="application/x-shockwave-flash" allowfullscreen="true" allownetworking="internal" autoplay="false" wmode="transparent"></embed></center><br /> 
<br />link: <a href="http://www.youtube.com/watch?v=pQpr3W-YmcQ" target="_blank" rel="nofollow">http://www.youtube.com/watch?v=pQpr3W-YmcQ</a></div> 	
 
 *[quote=bsod]Probando[/quote]
 *<blockquote><div class="cita"><strong>bsod</strong> dijo:</div><div class="citacuerpo"><p>probando</p></div></blockquote>	
 *
 */
	//charset utf-8
	String encabezado1 ="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> \n \n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"es\" xml:lang=\"es\" > \n<head profile=\"http://purl.org/NET/erdf/profile\"> \n \n	<meta http-equiv=\"X-UA-Compatible\" content=\"chrome=1\" /> \n	<link rel=\"schema.dc\" href=\"http://purl.org/dc/elements/1.1/\" /> \n	<link rel=\"schema.foaf\" href=\"http://xmlns.com/foaf/0.1/\" /> \n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> \n\n\n<meta name=\"revisit-after\" content=\"1 days\" /> \n<meta name=\"title\" content=\"Previsualizacion del post\" /> \n<meta property=\"dc:date\" content=\"2011-01-05 13:47:08\"/> \n<meta property=\"dc:creator\" content=\"PosT!NGA\" /> \n<link rel=\"prev\" href=\"/prev.php?id=8643952\" /> \n<link rel=\"next\" href=\"/next.php?id=8643952\" /> \n<link rel=\"alternate\" type=\"application/atom+xml\" title=\"Comentarios del post\" href=\"/rss/comentarios/8643952\" /> \n<link rel=\"alternate\" type=\"application/atom+xml\" title=\"Post del usuario\" href=\"/rss/posts-usuario/103290\" /> \n \n<title> \nPreview del post</title> \n \n<link href=\"http://o1.t26.net/images/css/beta_estilos3.css?5.4\" rel=\"stylesheet\" type=\"text/css\" /> \n<link rel=\"shortcut icon\" href=\"http://o1.t26.net/images/favicon.ico\" type=\"image/x-icon\" /> \n<link rel=\"apple-touch-icon\" href=\"http://o1.t26.net/images/apple-icon.png\" /> \n<link rel=\"search\" type=\"application/opensearchdescription+xml\" title=\"Taringa!\" href=\"http://www.taringa.net/lab/opensearch/taringa.xml\" /> \n \n \n \n \n \n \n \n<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js\" type=\"text/javascript\"></script> \n<script src=\"http://o1.t26.net/images/js/es/beta_acciones2.js?6.6.1\" type=\"text/javascript\"></script> \n<!--[if IE 6]>\n<script src=\"http://o1.t26.net/images/js/DD_belatedPNG_0.0.8a-min.js\"></script>\n<script>DD_belatedPNG.fix('#logo a,li, li a, .systemicons, .categoriaPost,.thumb-clima');</script>\n<script src=\"http://o1.t26.net/images/js/bgiframe.js\"></script>\n<![endif]--> \n \n<script type=\"text/javascript\"> \nvar global_data={\nuser_key:'',\npostid:'8643952',\ncomid:'',\ntemaid:'',\nimg:'http://o1.t26.net/'\n};\n$(document).ready(function(){\ntimelib.current = 1296535170;\ntimelib.upd();\n})\n</script> \n \n<script type=\"text/javascript\" src=\"http://partner.googleadservices.com/gampad/google_service.js\"></script> \n \n<script type=\"text/javascript\"> \n	GS_googleAddAdSenseService(\"ca-pub-5717128494977839\");\n	GS_googleEnableAllServices();\n</script> \n \n \n \n<script type=\"text/javascript\"> \n	GA_googleAddAttr(\"k\", \"tierra, Wallpaper, dinamico, xplanetfx\");	\n</script> \n \n \n<script type=\"text/javascript\"> \n	GA_googleAddAttr(\"d\", \"no\");\n	GA_googleAddAttr(\"s\", \"m\");\n	GA_googleAddAttr(\"e\", \"65\");\n	GA_googleAddAttr(\"p\", \"buenos-aires\");\n	GA_googleAddAttr(\"c\", \"linux\");\n	GA_googleAddAttr(\"de\", \"no\");\n</script> \n \n \n \n<script type=\"text/javascript\"> \n	GA_googleUseIframeRendering();\n</script> \n \n</head> \n<body> \n<div id=\"fb-root\"></div> \n<script type=\"text/javascript\">window.fbAsyncInit = facebook_ready;(function(){var e=document.createElement('script');e.src=document.location.protocol+'//connect.facebook.net/es_LA/all.js';e.async=true;document.getElementById('fb-root').appendChild(e)}())</script> \n \n<div class=\"brandday\"> \n<div id=\"mask\"></div> \n<div id=\"mydialog\"></div> \n<div class=\"rtop\"></div> \n<div id=\"maincontainer\"> \n<div id=\"head\"> \n	<div id=\"logo\"> \n		<a title=\"Taringa!\" id=\"logoi\"><img src=\"http://o1.t26.net/images/space.gif\" border=\"0\" alt=\"Taringa!\" title=\"Taringa!\" align=\"top\" /></a> \n	</div> \n \n	\n \n\n</div> \n \n<script type=\"text/javascript\"> \n	var menu_section_actual = 'Posts';\n</script> \n\n \n\n<div id=\"cuerpocontainer\"> \n<!-- inicio cuerpocontainer --> \n \n<a name=\"cielo\"></a> \n<div class=\"post-wrapper\"> \n \n	<!-- Perfil --> \n	<div class=\"post-autor vcard\"> \n		<div class=\"box_title\"> \n			<div class=\"box_txt post_autor\">Posteado por:</div> \n			<div class=\"box_rrs\"> \n				<div class=\"box_rss\"> \n					\n						<span style=\"position:relative;\"><img border=0 src=\"http://o1.t26.net/images/big1v12.png\" style=\"position:absolute; top:-354px; clip:rect(352px 16px 368px 0px);\"/><img border=0 src=\"http://o1.t26.net/images/space.gif\" style=\"width:14px;height:12px\" /></span>					\n				</div> \n			</div> \n		</div> \n		<div class=\"box_cuerpo\" typeof=\"foaf:Person\"> \n			<div class=\"avatarBox\" rel=\"foaf:img\"> \n				\n					<img src=\"http://dl.dropbox.com/u/155504/imagenes/postinga120x120.jpg\" class=\"avatar\"  title=\"Ver perfil de PosT!NGA\" onerror=\"error_avatar(this)\" /> \n				\n			</div> \n			<a rel=\"dc:creator\" property=\"foaf:nick\" class=\"url fn n\" > \n				<span class=\"given-name\">PosT!NGA</span> \n			</a> \n			<br /> \n			<span class=\"title\">New Full User</span> \n			<br /> \n \n						<span style=\"float: left; width: 16px; height: 16px; background: url(http://o1.t26.net/images/big2v1.png); background-position: 0 -814px\" title=\"Offline\"></span> \n			\n			<span style=\"position:relative;\"><img border=0 src=\"http://o1.t26.net/images/big2v1.png\" style=\"position:absolute; top:-660px; clip:rect(660px 16px 676px 0px);\" alt=\"New Full User\" title=\"New Full User\" /><img border=0 src=\"http://o1.t26.net/images/space.gif\" style=\"width:17px;height:16px\" align=\"absmiddle\" /></span><span style=\"position:relative;\"><img border=0 src=\"http://o1.t26.net/images/big2v1.png\" style=\"position:absolute; top:-132px; clip:rect(132px 16px 148px 0px);\" alt=\"Hombre\" title=\"Hombre\" /><img border=0 src=\"http://o1.t26.net/images/space.gif\" style=\"width:16px;height:16px\" align=\"absmiddle\" /></span>			<span class=\"adr\"> \n			<img class=\"country-name\" title=\"Argentina\" src=\"http://o1.t26.net/images/flags/ar.png\" width=\"16\" height=\"11\" align=\"absmiddle\" alt=\"Argentina\" hspace=\"3\" /> \n			</span> \n \n			<img align=\"absmiddle\" src=\"http://o1.t26.net/images/icon-mensajes-recibidos.gif\" title=\"Enviar mensaje privado\" alt=\"Enviar mensaje privado\" /> \n \n			\n			<hr class=\"divider\"/> \n			<div class=\"metadata-usuario\"> \n \n				<span class=\"nData user_follow_count\">100000</span> \n				<span class=\"txtData\">Seguidores</span> \n \n				<span class=\"nData\">100000</span> \n				<span class=\"txtData\">Puntos</span> \n \n				<span class=\"nData\"><a style=\"color: #0196ff\"\">1</a></span> \n				<span class=\"txtData\">Post</span> \n \n				<span class=\"nData\" style=\"color: #456c00\"></span> \n				<span class=\"txtData\">Sin Comentarios</span> \n \n			\n						</div> \n		</div> \n \n		\n		<center> \n</center><br /> \n\n	</div><!-- Perfil --> \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n	<!-- Cuerpo --> \n		<div class=\"post-contenedor\"> \n		<div class=\"post-title\"> \n			\n			<h1 property=\"dc:title\">";
	String encabezado2 ="</h1> \n			\n		</div> \n		<div class=\"post-contenido\"> \n										\n						\n								<center> \n</center>								\n				<span property=\"dc:content\"> \n";
	String pie="<div class=\"compartir-mov\" style=\"text-align: right; color:#888; font-size: 14px;margin: 30px 0 10px\"> \n					<div class=\"m-left\"> \n					</div> \n					\n					<div class=\"m-right\"> \n					</div> \n										<ul class=\"post-compartir clearbeta\"> \n						<li class=\"min-icon\"><img src=\"http://o1.t26.net/images/sonico_32.png\" alt=\"Sonico\" title=\"Sonico\" /></li> \n						<li class=\"min-icon\"><img src=\"http://o1.t26.net/images/delicious_32.png\" alt=\"Delicious\" title=\"Delicious\" /></li> \n						<li class=\"min-icon\"><img alt=\"\" title=\"Enviar a un amigo\" src=\"http://o1.t26.net/images/email_32.png\" /></li> \n \n<script type=\"text/javascript\"> \n	$(document).ready(function(){\n		$.getScript('http://platform.twitter.com/widgets.js');\n		$.getScript('http://static.ak.fbcdn.net/connect.php/js/FB.Share', function(){\n			$('.FBConnectButton_Text').html('Me gusta');\n			$('.fb_share_count_inner').html('0');\n		});\n	});\n</script> \n \n						<li class=\"share-big\"><a class=\"twitter-share-button\" data-count=\"vertical\" data-via=\"taringa\" data-lang=\"es\" ></a></li> \n						<li class=\"share-big\"><a name=\"fb_share\" share_url=\"\" type=\"box_count\" href=\"\"></a></li> \n						<li class=\"share-big\"> \n						 	<span class=\"share-t-count\">0</span> \n							<a class=\"share-t\"></a> \n						</li> \n						<li class=\"txt-movi\">Compartir en:</li> \n					</ul> \n				</div> \n		</div><!-- Cuerpo --> \n		\n \n \n \n</body> \n</html> ";

	
	
	public Bbcode2html() {
	

	}
	
	
	
	public String convertir(String str) {
		
		if (str!=null) {
		str=reempSize(str);
		str=reempBr(str);
		str=reempIBU(str);
		//if (str.contains("[video]")) str=reempYoutube(str);
		str=reempSwf(str);
		str=reempURL(str);
		str=reempImg2(str);
		str=reempImg(str);
		str=reempColor(str);
		str=reempAlign(str);
		str=reempCode(str);
		str=reempFont(str);
		str=ref(str);
		str=reempQuoteEqual(str);
		str=reempQuote(str);
		str=finales(str);
		str=div(str);
		return str;
		}
		else return "";
	}
	private static String  reempQuoteEqual(String str) {
	
		Pattern patron2 = Pattern.compile("(\\[quote=+)([\\+\\~\\%\\=\\?A-Za-z0-9\\.\\:\\-\\_/]*+)(\\])");
		Matcher matcher = patron2.matcher(str);
			
		boolean matchea;
		matchea=matcher.find();
		
		
		while (matchea) {
			
			str=(str.replace(matcher.group(0),"<blockquote><div class=\"cita\"><strong>"+matcher.group(2)+"</strong> dijo:</div><div class=\"citacuerpo\"><p>"));
			matchea=matcher.find();
			
		}

		return str;
		
	}


private static String  reempQuote(String str) {
		
		
		Pattern patron2 = Pattern.compile("(\\[quote+)([\\+\\~\\%\\=\\?A-Za-z0-9\\.\\:\\-\\_/]*+)(\\])");
		Matcher matcher = patron2.matcher(str);
			
		boolean matchea;
		matchea=matcher.find();
		
		
		while (matchea) {
			
			str=(str.replace(matcher.group(0),"<blockquote><div class=\"cita\"><strong>"+matcher.group(2)+"</strong> dijo:</div><div class=\"citacuerpo\"><p>"));
			matchea=matcher.find();
			
		}

		return str;
		
	}
	
	
	
		
	private static String  reempYoutube(String str) {
		
		/*
		 *
<br /><center><div style="border: 2px solid #DADEE1; width:640px"><iframe width="640" height="390" frameborder="0" src="http://www.youtube.com/embed/bxUiHNyO04c?wmode=transparent" allowfullscreen></iframe><a href="http://ads.us.e-planning.net/ei/3/46bb/4161ed037ea3390b?it=i&p=d7e0e558a67616b4" target="_blank"><img src="http://o1.t26.net/images/anunciantes/ARG_taringa_640x35_oro_dorado.jpg" width="640px" width="35px" /></a></div><img src="http://ads.us.e-planning.net/eb/3/46bb/4161ed037ea3390b?o=i&p=d7e0e558a67616b4" width="1px" height="1px" /></center>		</span>

		 * 
		 * 
		 */

		Pattern patron2 = Pattern.compile("(\\[video]+)([\\+\\~\\#\\&\\;\\%\\=\\?A-Za-z0-9\\.\\:\\-\\_/]+)(\\[/video])");
		Matcher matcher = patron2.matcher(str);

		
		
		
		
		boolean matchea;
		matchea=matcher.find();
		while (matchea) {
		int inicio=matcher.group(2).indexOf("v=")+2;
		int fin=matcher.group(2).indexOf('&',inicio);
		if (fin==-1) fin=matcher.group(2).length();
		String substring = matcher.group(2).substring(inicio,fin);
		
		
		
			str=(str.replace(matcher.group(0),"<br /><center><div style=\"border: 2px solid #DADEE1; width:640px\"><iframe width=\"640\" height=\"390\" frameborder=\"0\" src=\"http://www.youtube.com/embed/"+substring+
					 "?wmode=transparent\" allowfullscreen></iframe><a href=\"http://ads.us.e-planning.net/ei/3/46bb/4161ed037ea3390b?it=i&p=d7e0e558a67616b4\" target=\"_blank\"></a></div><img src=\"http://ads.us.e-planning.net/eb/3/46bb/4161ed037ea3390b?o=i&p=d7e0e558a67616b4\" width=\"1px\" height=\"1px\" /></center>		</span>")); 
			matchea=matcher.find();
			
		}
		
		return str;
		
	}
	
	
	
private static String  reempSwf(String str) {
		
		
		Pattern patron2 = Pattern.compile("(\\[swf]+)([\\+\\~\\#\\%\\=\\?A-Za-z0-9\\.\\:\\-\\_/]+)(\\[/swf])");
		Matcher matcher = patron2.matcher(str);
			
		boolean matchea;
		matchea=matcher.find();
		
		while (matchea) {
			str=(str.replace(matcher.group(0),"<div style=\"text-align: center\"><br />" +
					"<center><embed src=\""+matcher.group(2)+" \" quality=high width=\"640px\" height=\"385px\" " +
							"type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allownetworking=\"internal\"" +
							" autoplay=\"false\"</embed></center></div>")); 
			matchea=matcher.find();
			
		}

		return str;
		
	}
	
	
	
	
	
	
	
private static String reempIBU(String str) {
	
	str=str.replaceAll("\\[i]","<i>");
	str=str.replaceAll("\\[/i]","</i>");
	str=str.replaceAll("\\[b]","<b>");
	str=str.replaceAll("\\[/b]","</b>");
	str=str.replaceAll("\\[u]","<u>");
	str=str.replaceAll("\\[/u]","</u>");
	return str;
	
}
	
private static String  reempAlign(String str) {
		
		
		Pattern patron2 = Pattern.compile("(\\[align=+)([a-zA-Z]+)(\\])");
		Matcher matcher = patron2.matcher(str);
			
		boolean matchea;
		matchea=matcher.find();
		
		while (matchea) {
			
			str=(str.replace(matcher.group(0),"<div style=\"text-align: "+matcher.group(2)+"\">"));
			matchea=matcher.find();
			
		}
	
		return str;
		
	}


private static String reempBr (String str) {
	return (str.replaceAll("(\r\n|\r|\n|\n\r)", "<br>"));
	
	
}

private static String reempCode (String str) {
	str=str.replaceAll("\\[code\\]","<code><span style=\"color: #000000\">");
	return str.replaceAll("\\[/code\\]","</span> </code>");
	
	
}



//revisar que no esta bien




	
private static String  reempColor(String str) {
	
	
	Pattern patron2 = Pattern.compile("(\\[color=+)([\\#A-Za-z0-9]+)(\\])");
	Matcher matcher = patron2.matcher(str);
		
	boolean matchea;
	matchea=matcher.find();
		while (matchea) {
		str=(str.replace(matcher.group(0),"<span style=\"color: "+matcher.group(2)+";\">"));
		matchea=matcher.find();
		
	}

	return str;
	
}





private static String  reempSize(String str) {
	
	
	Pattern patron2 = Pattern.compile("(\\[size=+)([0-9a-zA-Z]+)(\\])");
	Matcher matcher = patron2.matcher(str);
		
	boolean matchea;
	matchea=matcher.find();
	
	while (matchea) {
		str=(str.replace(matcher.group(0),"<span style=\"font-size: "+matcher.group(2)+"pt;\">"));
		matchea=matcher.find();
		
	}

	return str;
	
}

private static String reempEscapes(String str) {
	/*
For the < type &lt;
For the > type &gt;
For the © type &copy;
For the & type &amp;
For the " type &quot;*/
	str=str.replaceAll("<","&lt;");
	str=str.replaceAll(">","&gt;");
	str=str.replaceAll("©","&copy;");
	str=str.replaceAll("\"","&quot;");
	return str;
}

private static String  reempURL(String str) {
	
	
	Pattern patron2 = Pattern.compile("(\\[url=+)([\\+\\~\\#\\!\\%\\=\\?\\&A-Za-z0-9\\.\\:\\-\\_/]+)(\\])");
	Matcher matcher = patron2.matcher(str);
		
	boolean matchea;
	matchea=matcher.find();
	
	while (matchea) {
		str=(str.replace(matcher.group(0),"<a href=\""+matcher.group(2)+"\" target=\"_blank\" rel=\"nofollow\">"));
		matchea=matcher.find();
		
	}

	return str;
	
}


private static String  reempImg(String str) {
	
	
	Pattern patron2 = Pattern.compile("(\\[img=+)([\\+\\(\\)\\~\\#\\!\\%\\=\\?\\&A-Za-z0-9\\.\\:\\-\\_/]+)(\\])");
	Matcher matcher = patron2.matcher(str);
		
	boolean matchea;
	matchea=matcher.find();
	
	while (matchea) {
		str=(str.replace(matcher.group(0),"<img class=\"imagen\" border=\"0\" src=\""+matcher.group(2)+"\"/>"));
		matchea=matcher.find();
		
	}

	return str;
	
}
	
	

private static String  reempImg2(String str) {
	
	
	Pattern patron2 = Pattern.compile("(\\[img\\]+)([\\+\\~\\%\\=\\?\\&A-Za-z0-9\\.\\:\\-\\_/]+)(\\[/img\\])");
	Matcher matcher = patron2.matcher(str);
		
	boolean matchea;
	matchea=matcher.find();
	
	while (matchea) {
		str=(str.replace(matcher.group(0),"<img class=\"imagen\" border=\"0\" src=\""+matcher.group(2)+"\"/>"));
		matchea=matcher.find();
		
	}

	return str;
	
}




	private static String  reempFont(String str) {
		
		
		Pattern patron2 = Pattern.compile("(\\[font=+)([\\sa-zA-Z]+)(\\])");
		Matcher matcher = patron2.matcher(str);
			
		boolean matchea;
		matchea=matcher.find();
		
		while (matchea) {
			str=(str.replace(matcher.group(0),"<span style=\"font-family: "+matcher.group(2)+"\">"));
			matchea=matcher.find();
			
		}
	
		return str;
		
	}
	
	private static String finales (String str) {
		
		str=str.replaceAll("\\[/font\\]","</span>");
		str=str.replaceAll("\\[/color\\]","</span>");
		str=str.replaceAll("\\[/size\\]","</span>");
		str=str.replaceAll("\\[/quote\\]","</p></div></blockquote>");
		
		return str;
		
	}
	
	private static String div (String str) {
		
		str=str.replaceAll("\\[/align\\]","</div>");
		return str;
		
	}
	
private static String ref (String str) {
		
		str=str.replaceAll("\\[/url\\]","</a>");
		return str;
		
	}
	


private static String emos (String str) {
	str=str.replaceAll(":\\)","[img=http://o2.t26.net/images/smiles/smile.gif]");
	str=str.replaceAll("X\\(","<img class=\"imagen\" border=\"0\" src=http://o2.t26.net/images/smiles/angry.gif/>");
	str=str.replaceAll(":cool:","[img=http://o2.t26.net/images/smiles/cool.gif]");
	str=str.replaceAll(":cry:","[img=http://o2.t26.net/images/smiles/crying.gif]");
	//str=str.replaceAll(":/","[img=http://o2.t26.net/images/smiles/unsure.gif]");
	str=str.replaceAll(":blaf:","[img=http://o2.t26.net/images/smiles/blaf.gif]");
	str=str.replaceAll(":winky:","[img=http://o2.t26.net/images/smiles/winky.gif]");
	str=str.replaceAll(":noo:","[img=http://o2.t26.net/images/smiles/sad2.gif]");
	str=str.replaceAll(":twisted:","[img=http://o2.t26.net/images/smiles/evil.gif]");
	str=str.replaceAll("^^","[img=http://o2.t26.net/images/smiles/grn.gif]");
	//str=str.replaceAll(":|","[img=http://o2.t26.net/images/smiles/huh.gif]");
	str=str.replaceAll(":D","[img=http://o2.t26.net/images/smiles/laughing.gif]");
	str=str.replaceAll(":oops:","[img=http://o2.t26.net/images/smiles/red.gif]");
	//str=str.replaceAll(":?","[img=http://o2.t26.net/images/smiles/s.gif]");
	str=str.replaceAll(":F","[img=http://o2.t26.net/images/smiles/drool.gif]");
	//str=str.replaceAll(":\\(","[img=http://o2.t26.net/images/smiles/sad.gif]");
	str=str.replaceAll(":P","[img=http://o2.t26.net/images/smiles/tongue.gif]");
	str=str.replaceAll(":roll:","[img=http://o2.t26.net/images/smiles/wassat.gif]");
	//str=str.replaceAll(";\\)","[img=http://o2.t26.net/images/smiles/wink.gif]");
	str=str.replaceAll(":crying:","[img=http://o2.t26.net/images/smiles/cry.gif]");
	str=str.replaceAll(":bobo:","[img=http://o2.t26.net/images/smiles/bobo.gif]");
	str=str.replaceAll(":grin:","[img=http://o2.t26.net/images/smiles/grin.gif]");
	str=str.replaceAll(":alaba:","[img=http://o2.t26.net/images/smiles/alabama.gif]");
	str=str.replaceAll(":lpmqtp:","[img=http://o2.t26.net/images/smiles/lpmqtp.gif]");
	str=str.replaceAll(":idiot:","[img=http://o2.t26.net/images/smiles/idiot.gif]");
	str=str.replaceAll(":shrug:","[img=http://o2.t26.net/images/smiles/shrug.gif]");
	str=str.replaceAll(":8S:","[img=http://o2.t26.net/images/smiles/8s.gif]");
	str=str.replaceAll(":]","[img=http://o2.t26.net/images/smiles/5.gif]");
	str=str.replaceAll(":blind:","[img=http://o2.t26.net/images/smiles/15.gif]");
	str=str.replaceAll(":buaa:","[img=http://o2.t26.net/images/smiles/17.gif]");
	str=str.replaceAll(":cold:","[img=http://o2.t26.net/images/smiles/cold.gif]");
	str=str.replaceAll(":hot:","[img=http://o2.t26.net/images/smiles/hot.gif]");
	/*str=str.replaceAll(":love:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":globo:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":zombie:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":man:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":metal:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":mario:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":info:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":exc:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":q:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":NO:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":OK:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":WOW:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":LOL:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":oo:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":RIP:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":alien:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":trago:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":money:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":culo:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":auto:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":lala:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":fantasma:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":buenpost:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":GET A LIFE:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":headbang:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":limon:","[img=http://o2.t26.net/images/smiles/grn.gif]");
	str=str.replaceAll(":verde:"		,"[img=http://o2.t26.net/images/smiles/grn.gif]");
	*/
	return str;
}



//en fase de pruebas. Iso-8851-1
/*
 * private String reempAcentos(String str) {
	str.replaceAll("á","&aacute;");
	str.replaceAll("é","&eacute;;");
	str.replaceAll("í","&iacute;;");
	str.replaceAll("ó","&oacute;");
	str.replaceAll("ú","&uacute;");
	str.replaceAll("Á","&Aacute;");
	str.replaceAll("É","&Eacute;");
	str.replaceAll("Í","&Iacute;");
	str.replaceAll("Ó","&Oacute;");
	str.replaceAll("Ú","&Uacute;");
	str.replaceAll("ñ","&ntilde;");
	str.replaceAll("Ñ","&Ntilde;");
	str.replaceAll("'","&acute;");
	str.replaceAll("Â¿","&iquest;");
	str.replaceAll("!","&iexcl;");
		
	
	return str;
}


*/


private String html(String tipo) throws IOException
{
	InputStream is;
	
  if (tipo.equals("pre")) is = getClass().getResourceAsStream("prevOffline"); 
    else  is = getClass().getResourceAsStream("pos");
 
  InputStreamReader isr = new InputStreamReader(is);
  BufferedReader br = new BufferedReader(isr);
  String line;
  String resultado="";
  while ((line = br.readLine()) != null) 
  {
    resultado=resultado+line+"\n";
  }
  br.close();
  isr.close();
  is.close();
  return resultado;
}
public String procesar(String str,String titulo,boolean bypass) {
	String post="";
	if (!bypass) {
		
		
		
		
		
	//str corresponde al texto en bbcode
		str=reempEscapes(str);
		str=reempSize(str);
	str=reempBr(str);
	str=reempIBU(str);
	//str=emos(str);
	if (str.contains("[video]")) str=reempYoutube(str);
	if (str.contains("[swf="))str=reempSwf(str);
	str=reempURL(str);
	str=reempImg2(str);
	str=reempImg(str);
	str=reempColor(str);
	
	str=reempAlign(str);
	str=reempCode(str);
	str=reempFont(str);
	str=ref(str);
	str=reempQuoteEqual(str);
	
	str=reempQuote(str);
	str=finales(str);
	str=div(str);
	
	}
	
	
	{
		try {
			post=html("pre")+"\n<h1 property=\"dc:title\" class=\"post-title\">"+titulo+"</h1>\n"+str+html("pos");
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
	}
	return post;
		
	
}

} 

